﻿using HomagChina.CCT.Router;
using HomagGroup.Base.UI.Windows;
using System;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;

namespace HomagChina.CCT
{
    public partial class App : Application
    {
        public App()
        {
        }

        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            string imagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.png");
            BitmapImage imageSource = null;

            await Task.Run(() =>
            {
                // 在非 UI 线程上加载图像数据
                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(imagePath, UriKind.Absolute);
                bitmap.CacheOption = BitmapCacheOption.OnLoad;
                bitmap.EndInit();
                bitmap.Freeze();
                Application.Current.Dispatcher.Invoke(() =>
                {
                    imageSource = bitmap;
                });
            });

            SplashScreenWindow _SplashScreenWindow = new SplashScreenWindow();

            _SplashScreenWindow.OnStartup(imageSource, "HomagChina Intelligence Platform Solution");

            await Task.Delay(3000);
            _SplashScreenWindow.Close();
            new RouterModel();
        }
    }
}